﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace JiveMessenger.Views
{
    public enum MemoryBoxResult { Yes, YesToAll, No, NoToAll, Cancel }

    /// <summary>
    /// Interaction logic for YesToAllDialog.xaml
    /// </summary>
    public partial class MemoryBox : Window
    {
        // Internal values
        MemoryBoxResult lastResult = MemoryBoxResult.Cancel;
        MemoryBoxResult result = MemoryBoxResult.Cancel;

        public MemoryBox(Window owner)
        {
            this.Owner = owner;
            this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            InitializeComponent();
            RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);
        }

        #region Properties
        public String LabelText
        {
            get { return this.TxtBlockInfo.Text; }
            set
            {
                this.TxtBlockInfo.Text = value;
                //   UpdateSize();
            }
        }

        public MemoryBoxResult Result
        {
            get { return this.result; }
            set { this.result = value; }
        }
        #endregion

        private void ButtonYes_Click(object sender, RoutedEventArgs e)
        {
            result = MemoryBoxResult.Yes;
            lastResult = MemoryBoxResult.Yes;
            this.Hide();
           // DialogResult = true;
        }

        private void ButtonYesToAll_Click(object sender, RoutedEventArgs e)
        {
            result = MemoryBoxResult.Yes;
            lastResult = MemoryBoxResult.YesToAll;
            this.Hide();
          //  DialogResult = true;
        }

        private void ButtonNo_Click(object sender, RoutedEventArgs e)
        {
            result = MemoryBoxResult.No;
            lastResult = MemoryBoxResult.No;
            this.Hide();
           // DialogResult = false;
        }

        private void ButtonNoToAll_Click(object sender, RoutedEventArgs e)
        {
            result = MemoryBoxResult.No;
            lastResult = MemoryBoxResult.NoToAll;
          //  DialogResult = false;
            this.Hide();
        }

        private void ButtonCancel_Click(object sender, RoutedEventArgs e)
        {
            result = MemoryBoxResult.Cancel;
            lastResult = MemoryBoxResult.Cancel;
          //  DialogResult = null;
            this.Hide();
        }
        #region Public Methods
        /// <summary>
        /// Call this function instead of ShowDialog, to check for remembered
        /// result.
        /// </summary>
        /// <returns></returns>
        private MemoryBoxResult ShowMemoryDialog()
        {
            result = MemoryBoxResult.Cancel;
            if (lastResult == MemoryBoxResult.NoToAll)
            {
                result = MemoryBoxResult.No;
            }
            else if (lastResult == MemoryBoxResult.YesToAll)
            {
                result = MemoryBoxResult.Yes;
            }
            else
            {
                ShowDialog();
            }
            return result;
        }

        public MemoryBoxResult ShowMemoryDialog(String label, string title)
        {
            this.Title = title;
            LabelText = label;
            return ShowMemoryDialog();
        }
        #endregion
    }
}
